/***************************************************************************
/
/ the StoryController class manages all the user actions related
/ to viewing Biographies; both the list of all Biographies and an
/ individual Biography itself
/
/**************************************************************************/

class StoryController {


	//define the default redirection for the StoryController
    def index = { redirect( action : list, params : params ) }


    // the delete, save and update actions only accept POST requests
    def allowedMethods = [ delete : 'POST', save : 'POST', update : 'POST' ]


	//return a list of all story records
    def list = {

        [ storyList : Story.list( params ) ]

    }


	//show a specific story record
    def show = {

		//get the approriate record based on the passed in id parameter
        def story = Story.get( params.id )

		//check we have a valid record
        if( !story ) {

			//if the record is not found, return to the list page with en error message
            flash.message = "Story not found with id ${params.id}"
            redirect( action : list )

        }
        else {

			//redirect to the 'view' page for this record
			return [ story : story ]

		}
    }


}
